/*
 * Copyright (c) 2007 The Chai Team
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

import mx.controls.Alert;

/**
 * Convert a dollar string to cents. The string is assumed to contain only
 * numbers and optionally a decimal point followed by exactly two digits.
 * <p>
 * Example: toCents("14.23") = 1423
 * @return the number of cents corresponding to this dollar amount
 */
public function toCents(text:String):int
{
	if (text.indexOf('.') == -1)
		return (100 * parseInt(text));

	var parts:Array = text.split('.', 2);
	var dollars:int = parseInt(parts[0]);
	var cents:int = parseInt(parts[1].substring(0,2));
	return (dollars * 100 + cents);

}

/**
 * Throws an error (with the message, if specified) if the given condition isn't
 * true.
 * @param condition
 * @param message (optional)
 */
public function assert(condition:Boolean, message:String = null):void
{
	if (message == null)
		message = "<no message given>";

	if (!condition)
		throw ("Assertion failed: " + message);
}
